package com.jzmy.specialist.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.plugins.Page;
import com.jzmy.specialist.dao.TrainingCertificatesDao;
import com.jzmy.specialist.entity.TrainingCertificates;
import com.jzmy.specialist.service.TrainingCertificatesService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 * <pre>
 * 培训证书
 * </pre>
 * <small> 2020-06-02 09:10:46 | lance</small>
 */
@Service
public class TrainingCertificatesServiceImpl extends ServiceImpl<TrainingCertificatesDao, TrainingCertificates> implements TrainingCertificatesService {


	@Override
	public TrainingCertificates findOneByKv(Object... params) {
		return getOne(this.convertToEntityWrapper(params));
	}

	private QueryWrapper<TrainingCertificates> convertToEntityWrapper(Object... params) {
		QueryWrapper<TrainingCertificates> ew = new QueryWrapper<>();
		if (params == null) {
			return ew;
		}
		for (int i = 0; i < params.length; i++) {
			if (i % 2 == 1 && params[i] != null && StringUtils.isNotBlank(params[i].toString())) {
				if(String.valueOf(params[i - 1]).equals("name")){
					ew.like((String) params[i - 1], params[i].toString());
				}else if(String.valueOf(params[i - 1]).equals("file_name")){
					ew.like((String) params[i - 1], params[i].toString());
				}else if(String.valueOf(params[i - 1]).equals("title")){
					ew.like((String) params[i - 1], params[i].toString());
				}else if(String.valueOf(params[i - 1]).equals("introduce")){
					ew.like((String) params[i - 1], params[i].toString());
				}else{
					ew.eq((String) params[i - 1], params[i].toString());
				}
			}
		}
		return ew;
	}
	@Override
	public Page<TrainingCertificates> findPageList(int current, int number, Long userId) {

		Page<TrainingCertificates> page = new Page<TrainingCertificates>(current , number);
		return page.setRecords(this.baseMapper.findPageList(page , userId));
	}

	@Override
	public String selCerNumber(String cerNums){
		return baseMapper.selCerNumber(cerNums);
	}
	
	@Override
	public String selByCerNumber(String cerNums){
		return baseMapper.selByCerNumber(cerNums);
	}

	@Override
	public List<Map> selImgUrls(Map map){
		return baseMapper.selImgUrls(map);
	}

	@Override
	public List<Map> selNoSaleImgUrls(Map map){
		return baseMapper.selNoSaleImgUrls(map);
	}
}
